import {
  reqAddOrganization,
  reqOrganizationDetail,
  reqOrganizationList,
} from '@/api/ibd'
import { defineStore } from 'pinia'

let typeDict = {
  cityInvest: '城投企业',
  bizInvest: '产投企业',
  finInst: '金融机构',
  creditor: '评级机构',
  auditor: '审计机构',
  lawfirm: '律师事务所',
  other: '其他',
}

let statusDict = {
  1: '建立联系',
  2: '初步沟通',
  3: '开展项目',
  0: '失去联系',
}

let useIbdStore = defineStore('IBD', {
  state: () => {
    return {
      organizationObj: {},
      orgList: [],
      orgDetail: {},
    }
  },
  actions: {
    async addOrganization(data) {
      let resp = await reqAddOrganization(data)
      if (resp.code === 200) {
        return 'OK'
      } else {
        return Promise.reject('添加失败')
      }
    },
    getOrganiazaionList(dataList) {
      this.orgList = dataList
      this.orgList.forEach((item) => {
        if (Object.keys(statusDict).includes(item.status)) {
          item.status = statusDict[item.status]
          // 把记录值调整为具体文字，到时候再看看网课有没有更好的方法
        }
        if (Object.keys(typeDict).includes(item.type)) {
          item.type = typeDict[item.type]
        }
      })
    },
    async getOrganizationDetail(id) {
      let resp = await reqOrganizationDetail(id)
      if (resp.code === 200) {
        this.orgDetail = resp.data.detail
      }
    },
  },
  getters: {
    // selectorChange(){
    // }
  },
})

export default useIbdStore
